Overview | Package | Class | Tree | Deprecated | Index | Help |
Java Platform 1.1.7 |
||
PREV CLASS | NEXT CLASS | FRAMES | NO FRAMES | ||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.sun.java.swing.table.AbstractTableModel | +--com.sun.java.swing.table.DefaultTableModel
Note:
The DefaultTableModel's API contains the methods addColumn(),
removeColumn(), but not methods to insert a column at an index
nor methods to move the columns. This is because JTable does
not display the columns based on the order of the columns in
this model. So rearranging them here doesn't do much. See
the column ordering methods in TableColumnModel.
Warning: serialized objects of this class will not be compatible with future swing releases. The current serialization support is appropriate for short term storage or RMI between Swing1.0 applications. It will not be possible to load serialized Swing1.0 objects with future releases of Swing. The JDK1.2 release of Swing will be the compatibility baseline for the serialized form of Swing objects.
Field Summary | |
java.util.Vector | columnIdentifiers
The Vector of column identifiers |
java.util.Vector | dataVector
The Vector of Vector of Object values |
Fields inherited from class com.sun.java.swing.table.AbstractTableModel | |
listenerList |
Constructor Summary | |
DefaultTableModel()
Constructs a default DefaultTableModel which is a table of zero columns and zero rows. |
|
DefaultTableModel(int numRows,
int numColumns)
Constructs a DefaultTableModel with numRows and numColumns of null object values. |
|
DefaultTableModel(java.util.Vector columnNames,
int numRows)
Constructs a DefaultTableModel with as many columns as there are elements in columnNames and numRows of null object values. |
|
DefaultTableModel(java.lang.Object[] columnNames,
int numRows)
Constructs a DefaultTableModel with as many columns as there are elements in columnNames and numRows of null object values. |
|
DefaultTableModel(java.util.Vector data,
java.util.Vector columnNames)
Constructs a DefaultTableModel and initializes the table by passing data and columnNames to the setDataVector() method. |
|
DefaultTableModel(java.lang.Object[][] data,
java.lang.Object[] columnNames)
Constructs a DefaultTableModel and initializes the table by passing data and columnNames to the setDataVector() method. |
Method Summary | |
void | addColumn(java.lang.Object columnName)
Add a column to the model. |
void | addColumn(java.lang.Object columnName,
java.util.Vector columnData)
Add a column to the model. |
void | addColumn(java.lang.Object columnName,
java.lang.Object[] columnData)
Adds a column to the model with name columnName. |
void | addRow(java.util.Vector rowData)
Add a row to the end of the model. |
void | addRow(java.lang.Object[] rowData)
Add a row to the end of the model. |
static java.util.Vector | convertToVector(java.lang.Object[] anArray)
Returns a Vector that contains the same objects as the array |
static java.util.Vector | convertToVector(java.lang.Object[][] anArray)
Returns a Vector of Vectors that contains the same objects as the array |
int | getColumnCount()
|
java.lang.String | getColumnName(int column)
|
java.util.Vector | getDataVector()
This returns the Vector of Vectors that contains the table's data values. |
int | getRowCount()
|
java.lang.Object | getValueAt(int row,
int column)
Returns an attribute value for the cell at row and column. |
void | insertRow(int row,
java.util.Vector rowData)
Insert a row at row in the model. |
void | insertRow(int row,
java.lang.Object[] rowData)
Insert a row at row in the model. |
boolean | isCellEditable(int row,
int column)
Returns true if the cell at row and column is editable. |
void | moveRow(int startIndex,
int endIndex,
int toIndex)
Moves one or more rows starting at startIndex to endIndex in the model to the toIndex. |
void | newDataAvailable(TableModelEvent event)
Equivalent to fireTableChanged. |
void | newRowsAdded(TableModelEvent event)
This method will make sure the new rows have the correct number of columns. |
void | removeRow(int row)
Remove the row at row from the model. |
void | rowsRemoved(TableModelEvent event)
Equivalent to fireTableChanged(). |
void | setColumnIdentifiers(java.util.Vector newIdentifiers)
Replaces the column identifiers in the model. |
void | setColumnIdentifiers(java.lang.Object[] newIdentifiers)
Replaces the column identifiers in the model. |
void | setDataVector(java.util.Vector newData,
java.util.Vector columnNames)
This replaces the current dataVector instance variable with the new Vector of rows, newData. |
void | setDataVector(java.lang.Object[][] newData,
java.lang.Object[] columnNames)
This replaces the value in the dataVector instance variable with the values in the array newData. |
void | setNumRows(int newSize)
Sets the number of rows in the model. |
void | setValueAt(java.lang.Object aValue,
int row,
int column)
Sets the object value for the cell at column and row. |
Methods inherited from class com.sun.java.swing.table.AbstractTableModel | |
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getColumnClass, getColumnName, isCellEditable, removeTableModelListener, setValueAt |
Methods inherited from class java.lang.Object | |
clone, equals, finalize, getClass, hashCode, notifyAll, notify, toString, wait, wait, wait |
Field Detail |
protected java.util.Vector dataVector
protected java.util.Vector columnIdentifiers
Constructor Detail |
public DefaultTableModel()
public DefaultTableModel(int numRows, int numColumns)
numRows
- The number of rows the table holds
numColumns
- The number of columns the table holdspublic DefaultTableModel(java.util.Vector columnNames, int numRows)
columnNames
- Vector containing the names of the new columns.
If this null then the model has no columns
numRows
- The number of rows the table holdspublic DefaultTableModel(java.lang.Object[] columnNames, int numRows)
columnNames
- Array containing the names of the new columns.
If this null then the model has no columns
numRows
- The number of rows the table holdspublic DefaultTableModel(java.util.Vector data, java.util.Vector columnNames)
data
- The data of the table
columnNames
- Vector containing the names of the new columns.public DefaultTableModel(java.lang.Object[][] data, java.lang.Object[] columnNames)
data
- The data of the table
columnNames
- The names of the columns.Method Detail |
public java.util.Vector getDataVector()
((Vector)getDataVector().elementAt(1)).elementAt(5);
You can directly alter the returned Vector. You can change the cell values, the number of rows. If you need to alter the number of columns in the model, you can do so with addColumn(), removeColumn(), or the setDataVector() methods. Once you have finished modifying the dataVector, you must inform the model of the new data using one of the notification methods. The notification methods will generate the appropriate TableModelListener messages to notify the JTable and any other listeners of this model.
public void setDataVector(java.util.Vector newData, java.util.Vector columnNames)
newData
- The new data vector
columnNames
- The names of the columnspublic void setDataVector(java.lang.Object[][] newData, java.lang.Object[] columnNames)
public void newDataAvailable(TableModelEvent event)
public void newRowsAdded(TableModelEvent event)
public void rowsRemoved(TableModelEvent event)
public void setColumnIdentifiers(java.util.Vector newIdentifiers)
newIdentifiers
- Vector of column identifiers. A null means
setting the model to zero columnspublic void setColumnIdentifiers(java.lang.Object[] newIdentifiers)
newIdentifiers
- Array of column identifiers. A null means
setting the model to zero columnspublic void setNumRows(int newSize)
newSize
- the new number of rowspublic void addColumn(java.lang.Object columnName)
columnName
- the identifier of the column being addedpublic void addColumn(java.lang.Object columnName, java.util.Vector columnData)
columnName
- the identifier of the column being added
columnData
- optional data of the column being addedpublic void addColumn(java.lang.Object columnName, java.lang.Object[] columnData)
public void addRow(java.util.Vector rowData)
rowData
- optional data of the row being addedpublic void addRow(java.lang.Object[] rowData)
rowData
- optional data of the row being addedpublic void insertRow(int row, java.util.Vector rowData)
row
- the row index of the row to be inserted
rowData
- optional data of the row being addedpublic void insertRow(int row, java.lang.Object[] rowData)
row
- the row index of the row to be inserted
rowData
- optional data of the row being addedpublic void moveRow(int startIndex, int endIndex, int toIndex)
Examples of moves:
1. moveRow(1,3,5);
a|B|C|D|e|f|g|h|i|j|k - before a|e|f|B|C|D|g|h|i|j|k - after 2. moveRow(6,7,1);
a|b|c|d|e|f|G|H|i|j|k - before a|G|H|b|c|d|e|f|i|j|k - after
startIndex
- the starting row index to be moved
endIndex
- the ending row index to be moved
toIndex
- the destination of the rows to be movedpublic void removeRow(int row)
row
- the row index of the row to be removedpublic int getRowCount()
public int getColumnCount()
public java.lang.String getColumnName(int column)
public boolean isCellEditable(int row, int column)
row
- the row whose value is to be looked up
column
- the column whose value is to be looked uppublic java.lang.Object getValueAt(int row, int column)
row
- the row whose value is to be looked up
column
- the column whose value is to be looked uppublic void setValueAt(java.lang.Object aValue, int row, int column)
aValue
- the new value. This can be null.
row
- the row whose value is to be changed
column
- the column whose value is to be changedprotected static java.util.Vector convertToVector(java.lang.Object[] anArray)
protected static java.util.Vector convertToVector(java.lang.Object[][] anArray)
Overview | Package | Class | Tree | Deprecated | Index | Help |
Java Platform 1.1.7 |
||
PREV CLASS | NEXT CLASS | FRAMES | NO FRAMES | ||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |